package cn.java79.quiz.service;

import cn.java79.quiz.dao.AdminMapper;
import cn.java79.quiz.dao.RoleMapper;
import cn.java79.quiz.entity.Admin;
import cn.java79.quiz.entity.Role;
import cn.java79.quiz.pojo.AjaxPage;
import cn.java79.quiz.util.MybatisUtil;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.apache.ibatis.session.SqlSession;

/**
 * @author oldliu
 * @since 1.0
 */
public class RoleService {
    public static final int PAGESIZE=10;
    public static RoleService ME=new RoleService();
    public AjaxPage<Role> search(String rolename, int pageNo){
        return this.search(rolename, pageNo,PAGESIZE);
    }
    public AjaxPage<Role> search(String rolename, int pageNo, int pageSize){
        SqlSession s = MybatisUtil.get();
        Page<Role> page = PageHelper.startPage(pageNo, pageSize);
        try {

            RoleMapper mapper = s.getMapper(RoleMapper.class);
            mapper.search(rolename);
            System.out.println(page.getPageNum()+">>>>>>>>>>>>>>>>>>>>>>>>>>");
            return new AjaxPage<Role>(page.subList(0, page.size()), page.getTotal(), page.getPageNum(), page.getPageSize(), page.getPages());
        } finally {
            MybatisUtil.close(s);
        }

    }
}
